<?php

class Application_Model_DbTable_Article extends Zend_Db_Table_Abstract
{

    protected $_name = 'article';
    
	public function showArticle(){
		
		$data = $this->fetchAll()->toArray();
		return $data;
		
	}
	
	public function getArticle($id){
		
		$id = (int)$id;
		$data = $this->fetchRow('id='.$id);
		if(!$data){
			throw new Exception("Nie można odnaleźć rekordu o numerze id $id");
		}
		return $data->toArray();
		
	}

	public function addArticle($name, $content, $dzial){
		
		$data = array(
			'name' => $name,
			'content' => $content,
			'dzial' => $dzial
		);
		$this->insert($data);
		
	}
	
	public function updateArticle($id, $name, $content, $dzial){
		
		$data = array(
			'name' => $name,
			'content' => $content,
			'dzial' => $dzial
			);
		$this->update($data, 'id='.$id);
		
	}
	public function deleteArticle($id){
		
		$this->delete('id=' . (int)$id);
		
	}
}

